package com.mty.kjtest.Http;

import com.mty.kjtest.Configure.HttpUrl;
import com.mty.kjtest.Model.MovieEntity;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import java.util.concurrent.TimeUnit;

/**
 * Created by 天宇 on 2017/6/30.
 * 网络请求封装
 */
public class HttpMethods {

    private static final int DEFAULT_TIMEOUT = 5;//默认超时时间
    protected static HttpMethods instance = null; //单例
    private Retrofit retrofit;
    private Network network;

    private HttpMethods() {
        OkHttpClient.Builder httpclientBuider = new OkHttpClient.Builder();
        httpclientBuider.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);

        retrofit = new Retrofit.Builder()
                .client(httpclientBuider.build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(HttpUrl.BaseUrl)
                .build();

        network=retrofit.create(Network.class);
    }


    public Network getNetwork() {
        return network;
    }









    public static HttpMethods getInstance() {
        if (instance == null) {
            synchronized (HttpMethods.class) {
                if (instance == null) {
                    instance = new HttpMethods();
                }
            }
        }
        return instance;
    }


}
